package com.motong.gongdan.vo.system.AssemblyWorkOrder.query;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;

import java.util.*;

@Data
@ApiModel("装配工单请求参数")
@Accessors(chain = true)
public class AssemblyListQuery {

    @ApiModelProperty("列表条件查询")
    private QueryData commonCondition = new QueryData();

    @ApiModelProperty("筛选方案条件")
    private QueryData searchPlanCondition = new QueryData();

    @ApiModelProperty(value = "页码")
    private Integer page = 1;

    @ApiModelProperty(value = "条数")
    private Integer limit = -1;

    @Data
    public static class QueryData {
        @ApiModelProperty(value = "单据编号")
        private String code;

        @ApiModelProperty(value = "创建人")
        private String createUserName;

        @ApiModelProperty(value = "创建时间起")
        private Date createTimeStart;

        @ApiModelProperty(value = "创建时间止")
        private Date createTimeEnd;

        @ApiModelProperty(value = "更新人")
        private String updateUserName;

        @ApiModelProperty(value = "更新时间起")
        private Date updateTimeStart;

        @ApiModelProperty(value = "更新时间止")
        private Date updateTimeEnd;

        @ApiModelProperty(value = "自定义查询条件(key为自定义字段id)")
        private Map<Integer, String> customFieldMap;

        @ApiModelProperty("装配工单id")
        private List<Long> ids;

        @ApiModelProperty(value = "页码")
        private Integer page = 1;

        @ApiModelProperty(value = "条数")
        private Integer limit = -1;

        @ApiModelProperty("排序列(创建时间 createTime, 更新时间 updateTime ,单据编号 code)")
        private String orderBy = "createTime";

        @ApiModelProperty("排序(ASC 升序, DESC 降序)")
        private String sort = "DESC";

        public void setSort(String sort) {
            List<String> columnList = Arrays.asList("DESC", "ASC");
            if (columnList.contains(sort)) {
                this.sort = sort;
            }
        }

        public void setOrderBy(String orderBy) {
            List<String> columnList = Arrays.asList("createTime", "updateTime", "code");
            if (columnList.contains(orderBy)) {
                this.orderBy = "temp.".concat(orderBy);
            }
        }

        @ApiModelProperty(value = "创建人id(多个,号隔开)")
        private String createUserIds;

        @ApiModelProperty(value = "更新人id(多个,号隔开)")
        private String updateUserIds;

        @ApiModelProperty(value = "createUserIdList", hidden = true)
        private List<String> createUserIdList = new ArrayList<>();

        @ApiModelProperty(value = "createUserIdList", hidden = true)
        private List<String> updateUserIdList = new ArrayList<>();

        public void setCreateUserIds(String createUserIds) {
            if (StringUtils.hasLength(createUserIds)) {
                createUserIdList = Arrays.asList(createUserIds.split(","));
            }
            this.createUserIds = createUserIds;
        }

        public void setUpdateUserIds(String updateUserIds) {
            if (StringUtils.hasLength(updateUserIds)) {
                updateUserIdList = Arrays.asList(updateUserIds.split(","));
            }
            this.updateUserIds = updateUserIds;
        }
    }
}
